 
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or (at
#  your option) any later version.
#
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

from RandomArray import *
from time import *

#
# in pseudoVisa.py there are all classes which are used to simulate some visadevices
#
# you can use this file insted of real instruments. The output which would be send to some instruments is
# sent to the console. And some random numbers are sent back
# 
# 
# Classes: 	GpibInstrument:	the functions defined in here are the same (main)-function which are defined in pyVisa
#

def get_instruments_list():
	return ("GPIB0::1 (1Arg)","GPIB0::2 (1Arg)","GPIB0::3 (2Arg)", "GPIB0::4 (2Arg,Liste)")

class Instrument(object):
	
	def __init__(self, board_number=0):
		print "new instrument on",board_number
		self.boardnumber=board_number
		self.counter=0
		seed()		
	
	def write(self, message):
		print "write:", self.boardnumber, message
		
	def ask(self, message):
		#print "ask:", self.boardnumber, message
		self.counter+=1
		sleep(0.1)
		s=str(uniform(-5,+5,3)[1])
		#raise NameError, 'HiThere'

		if self.boardnumber=="GPIB0::3 (2Arg)":
			print "ask:", self.boardnumber, message, " String:", str(self.counter)+","+s
			return str(self.counter)+","+s
		elif self.boardnumber=="GPIB0::4 (2Arg,Liste)":
			print "ask:", self.boardnumber, message, " String:", str(self.counter)+","+s
			return str(self.counter)+","+s+","+str(self.counter)+","+s+","+str(self.counter)+","+s
		
		else: 
			print "ask:", self.boardnumber, message, " String:", s
			return s
	
	def timeout(self,msecs):
		print "Neuer TimeOut: ",msecs
		
